import {mapGetters} from "vuex";
import * as GroupApi from '@/api/school/groupinfo.js';
import diyJson from '@/config/diy.js';
import {BASE_CONFIG} from "@/config/app";
import {isBlank} from "@/utils/util";

const app = getApp();

export const mixins =
    {
      computed: mapGetters(['uid', 'userInfo', 'shareInfo', 'schoolId']),
      components: {
      },
      data() {
        return {
          swiperCurrent: 0,

          btnDisabled: false,

          themConfig: diyJson.commonStyle,

          pageBody: {
            paddingBottom: 65,
          },
          groupInfo: {
            mainPic: []
          },
          num: 1,
          urlParams: undefined,
          statusNavProperties: { // 筛选条件
            title: "跑腿拼团详情",
            setStyle: diyJson.statusbar.setStyle,
            showLeft:true,
            showHome:true
          },
        };
      },

      onLoad: function (options) {
        let p = options.params;
        if (p) {
          // {"activityId":""}
          let params = JSON.parse(decodeURIComponent(p));
          this.urlParams = params;
          console.log("params", params)
          this.detailData(params.activityId);
        }
      },
      onPullDownRefresh() {
        uni.stopPullDownRefresh();
      },
      created() {
      },

      onShow() {

      },
      mounted() {
        // this.$refs.formPopup.open();
      },

      methods: {

        async detailData(id) {
          await GroupApi.groupDetail(id).then(res => {
            this.groupInfo = res.data
          });
        },

        copyLick(){

          uni.setClipboardData({
            data: BASE_CONFIG.H5WebHost+'/pages/school/group-detail/index?params='+encodeURIComponent(JSON.stringify(this.urlParams)),
            success: function () {
              uni.showToast({
                title: '参团链接已复制',
                icon: 'success',
                duration: 2000
              });
            }
          });
        },

        // 提交表单
        nowJoining() {

          if (this.groupInfo.state == 2||this.groupInfo.state == 1) {
            return;
          }

          // 是否认证注册信息
          if (isBlank(this.userInfo.phone) || isBlank(this.schoolId)) {

            uni.showToast({
              title: '需要先注册信息......',
              duration: 1000,
              icon: 'none'
            });

            setTimeout(() => {
              uni.navigateTo({
                url: '/pages/users/user_info/index',
              })
            }, 500)
            return false;
          }


          let params = {
            // ...this.groupInfo,
            activityId:this.groupInfo.id,
            num: this.num,
            marketTag: '团'
          }

          // this.$store.commit('SET_JUMP_INFO', params);

          params = encodeURIComponent(JSON.stringify(params));

          uni.navigateTo({
            url: `/pages/school/group-detail/submit/index?params=${params}`
          })
        },
        numChange(e) {
          console.log("num", e)
        },

        getApp() {
          return app;
        },
      },
      onReachBottom() {
      },
      onShareAppMessage() {
        return {
          title: '邀您参加【'+groupInfo.goods.goodsName+'】优惠拼团团',
          path: 'pages/school/group-detail/index?params='+encodeURIComponent(JSON.stringify(this.urlParams)), // 分享路径（推荐带参数）
          imageUrl: '' // 自定义分享图片（选填）
        }
      }
    }
